import java.awt.Graphics;
import java.awt.Image;

public class DragonflySprite extends BeeSprite {

	protected Image imageDragonflyLeft;
	protected Image imageDragonflyRight;
	protected Image deadDragonflyLeft;
	protected Image deadDragonflyRight;

	protected boolean isHit;
	protected boolean shouldDrawImage = false;

	public boolean getIsHit() {
		return isHit;
	}

	public void setIsHit(boolean isHit) {
		this.isHit = isHit;
	}

	public DragonflySprite(Gameloop gl, int x, int y) {
		super(gl);

		imageDragonflyLeft = ImageLoader.get()
				.read("/Images/DragonflyLeft.png");
		imageDragonflyRight = ImageLoader.get().read(
				"/Images/DragonflyRight.png");

		deadDragonflyLeft = ImageLoader.get().read(
				"/Images/DeadDragonflyLeft.png");
		deadDragonflyRight = ImageLoader.get().read(
				"/Images/DeadDragonflyRight.png");

		this.x = x;
		this.y = y;

		if (x < 0) {
			flagx = true;
		} else {
			flagx = false;
		}

		speedx = 4.5f;
		speedy = 3.0f;

		maxlimit = 40;
		value = 5;
		isHit = false;
	}

	public void update() {

		if (isHit) {
			deadpath();
			shouldDrawImage = true;
			return;
		}

		if (++compteur % speedLimit == 0) {

			speedLimit = random.nextInt(maxlimit) + 1;

			flagy = random.nextBoolean();
			compteur = 0;
		}

		x = (int) (x + (speedx * (flagx ? 1 : -1)));
	}

	public void draw(Graphics g) {

		if (!flagx && !isHit) {
			g.drawImage(imageDragonflyLeft, x, y, width, height, null);
		} else if (flagx && !isHit) {
			g.drawImage(imageDragonflyRight, x, y, width, height, null);
		} else if (isHit && !flagx) {
			g.drawImage(deadDragonflyLeft, x, y, width, height, null);
		} else {
			g.drawImage(deadDragonflyRight, x, y, width, height, null);
		}
	}
}
